package com.observed;

import java.util.ArrayList;
import java.util.List;

/**
 * 被观察者实现
 * 
 * @author zincredible
 * @date 2019-01-22 16:41:47
 */
public class BeobservedImpl implements IBeobserved {

	private List<Observed> observeds;

	public BeobservedImpl() {
		super();
		observeds = new ArrayList<>();
	}

	@Override
	public boolean registerObserved(Observed o) {
		return observeds.add(o);
	}

	@Override
	public boolean removeObserved(Observed o) {
		return observeds.remove(o);

	}

	@Override
	public void notifyObserved(String msg) {
		observeds.forEach(e -> e.update(msg));
	}

	@Override
	public void setInfo(String msg) {
		System.out.println("被观察者更新了消息：" + msg);
		notifyObserved(msg);
	}

}
